package site.service;

import java.sql.Connection;

import neoutil.CommonService;
import neoutil.DaoSupport;

import org.apache.log4j.Logger;

import site.dao.RoleDao;
import site.entity.Role;

public class RoleRepository extends CommonService {
	private static Logger log = Logger.getLogger(RoleRepository.class);

	public void saveRole(Role role) {
		Connection connection = null;
		try {
			connection = DaoSupport.getConnection();

			RoleDao roleDao = new RoleDao(connection);

			roleDao.save(role);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			closeConnection(connection);
		}
	}

	public Role getRoleById(int rid) {
		Role r = null;
		Connection connection = null;
		try {
			connection = DaoSupport.getConnection();

			RoleDao roleDao = new RoleDao(connection);

			r = roleDao.getById((long) rid);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			closeConnection(connection);
		}

		return r;
	}
}
